11/14/2017
data(diamonds) ggplot(diamonds, aes(x = carat, y = price, color = color))+ geom_point()
data(diamonds) ggplot(diamonds, aes(x = carat, y = price, color = color))+ geom_point() + scale_x_continuous(name = "Carat", breaks = 1:5, minor_breaks = NULL)+ scale_y_log10(name = "Price ($)")+ labs(color = "Color")
ggplot(diamonds, aes(x = carat, y = price, color=clarity, size = depth))+ geom_point()
# Requires the "hexbin" package to be installed ggplot(diamonds, aes(x = carat, y = price))+ geom_hex()
ggplot(diamonds, aes(x = cut, y = price)) + geom_boxplot() + scale_y_log10()+ labs(x = 'Cut',y = 'Price ($)') + theme(axis.text.x = element_text(angle = 45, hjust = 1))
ggplot(diamonds, aes(x = cut, y = price)) + geom_boxplot() + scale_y_log10()+ labs(x = 'Cut',y = 'Price ($)') + theme(axis.text.x = element_text(angle = 45, hjust = 1)) + coord_flip()
# Adding ggthemes
library(ggthemes) ggplot(diamonds, aes(x=carat, y = price, color = color))+ geom_point()+ theme_economist()
data(diamonds) ggplot(diamonds, aes(x = carat, y = price, color = color))+ geom_point()+ theme_fivethirtyeight()
data(diamonds) ggplot(diamonds, aes(x = carat, y = price, color = color))+ geom_point()+ theme_excel()
data(diamonds) ggplot(diamonds, aes(x = carat, y = price, color = color))+ geom_point()+ theme_wsj()
data(diamonds) ggplot(diamonds, aes(x = carat, y = price, color = color))+ geom_point()+ theme_stata()
data(diamonds) ggplot(diamonds, aes(x = carat, y = price, color = color))+ geom_point()+ theme_few()
suppressPackageStartupMessages(library(cowplot)) plt <- ggplot(diamonds, aes(x = carat, y = price, color=clarity))+ geom_point() plt
plt + background_grid(major = 'xy', minor = 'none')
plt1 <- ggplot(diamonds, aes(x = carat, y = price)) + geom_point()
plt2 <- ggplot(diamonds, aes(x = clarity, y = price)) + geom_boxplot()
cowplot::plot_grid(plt1, plt2, labels = c('A','B'))
plt3 <- ggplot(diamonds, aes(x = color, y = price)) + geom_boxplot()
cowplot::plot_grid(plt1, plt2, plt3, labels = c('A','B','C'), nrow=2)
library(ggExtra) p <- ggplot(diamonds, aes(x = carat, y = price)) + geom_point() ggMarginal(p, type = 'histogram')
library(survival) library(survminer) fit <- survfit(Surv(time, status) ~ sex, data = lung) ggsurvplot(fit, data = lung)
ggsurvplot(
fit,
data = lung,
size = 1, # change line size
palette =
c("#E7B800", "#2E9FDF"),# custom color palettes
conf.int = TRUE, # Add confidence interval
pval = TRUE, # Add p-value
risk.table = TRUE, # Add risk table
risk.table.col = "strata",# Risk table color by groups
legend.labs =
c("Male", "Female"), # Change legend labels
risk.table.height = 0.25, # Useful to change when you have multiple groups
ggtheme = theme_bw() # Change ggplot2 theme
)